// sgu344
// 题意：
//
// 题解：
// 简单题，bfs，dfs都行
//
// run: $exec < input
#include <iostream>
#include <queue>

struct data { int x, y; };

int const opt[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int const maxn = 1007;
bool vis[maxn][maxn];
int a[maxn][maxn];
int n, m;

bool inrange(int x, int y) { return (1 <= x && x <= n) && (1 <= y && y <= m); }

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> m;

	std::queue<data> q;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char ch; std::cin >> ch;
			if (ch == 'X') { q.push({i, j}); vis[i][j] = true; a[i][j] = 2; }
		}

	while (!q.empty()) {
		auto now = q.front(); q.pop();
		vis[now.x][now.y] = true;
		for (int i = 0; i < 4; i++) {
			int tx = now.x + opt[i][0];
			int ty = now.y + opt[i][1];
			if (!inrange(tx, ty) || vis[tx][ty]) continue;
			a[tx][ty]++;
			if (a[tx][ty] >= 2) {
				vis[tx][ty] = true;
				q.push({tx, ty});
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) ans += vis[i][j];
	std::cout << ans << "\n";
}

